﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CanDoo.Data.Entity;
using CanDoo.Oil.Core.Models;
using System.Data.Entity.Infrastructure.Annotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace CanDoo.Oil.Core.ModelConfigurations
{
    /// <summary>
    /// 实体类-数据表映射——采购单
    /// </summary>
    public class InOrderConfiguration : EntityConfigurationBase<InOrder>
    {
        /// <summary>
        /// 初始化一个<see cref="InOrderConfiguration"/>类型的新实例
        /// </summary>
        public InOrderConfiguration()
        {
             ToTable("buy_InOrder");
             this.Property(p => p.SupplierId).HasColumnName("SupplierId");
             this.HasRequired(p => p.Supplier).WithMany().HasForeignKey(p => p.SupplierId).WillCascadeOnDelete(false);

             this.Property(p => p.WarehouseId).HasColumnName("WarehouseId");
             this.HasRequired(p => p.Warehouse).WithMany().HasForeignKey(p => p.WarehouseId).WillCascadeOnDelete(false);

             this.Property(p => p.UserId).HasColumnName("UserId");
             this.HasRequired(p => p.User).WithMany().HasForeignKey(p => p.UserId).WillCascadeOnDelete(false);

            this.Property(p => p.Code)
                .IsRequired()
                .HasMaxLength(new int?(20))
                .HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("UX_InOrder_Code") { IsUnique = true }));
        }
    }
}
